import requests
# 浏览器配置对象
from selenium import webdriver
options = webdriver.ChromeOptions()
# 以开发者模式启动浏览器
options.add_experimental_option('excludeSwitches', ['enable-automation'])
# 屏蔽以开发者运行提示框
# options.add_experimental_option('useAutomationExtension', False)
# 屏蔽保存密码提示框
prefs = {'credentials_enable_service': False, 'profile.password_manager_enabled': False}
options.add_experimental_option('prefs', prefs)
# chrome 88 或更高版本的反爬虫特征处理
options.add_argument('--disable-blink-features=AutomationControlled')
# 浏览器对象
driver = webdriver.Chrome(options=options)
# 读取脚本 下载 stealth.min.js 到本地
with open('stealth.min.js', mode='r', encoding='utf-8') as f:
    string = f.read()
# 移除 selenium 中的爬虫特征
driver.execute_cdp_cmd('Page.addScriptToEvaluateOnNewDocument', {'source': string})

driver.get('http://jycg.hubei.gov.cn/info-query/jycgnoticeinfo/list.do?pageIndex=1&pageSize=12&type=4')
print(driver.get_cookies())

urls=[f'http://jycg.hubei.gov.cn/info-query/jycgnoticeinfo/list.do?pageIndex={i}&pageSize=12&type=4' for i in range(1,2)]

cookies = {}
for cookie in driver.get_cookies():
    cookies[cookie['name']] = cookie['value']


headers = {
    "Host":  "jycg.hubei.gov.cn"
}
for url in urls:
    response = requests.get(url=url,headers=headers,cookies=cookies)
    print(response.text)